<template>
  <div class="box6">
    <div class="title">
      <p>热门景区排行</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'

//获取节点
let charts = ref()

onMounted(() => {
  //获取echarts类的实例
  let mycharts = echarts.init(charts.value)
  //设置实例的配置项
  mycharts.setOption({
    //标题组件
    title: {
      text: '景区排行',
      link: 'https://www.baidu.com/',
      textStyle: {
        color: 'white',
        fontSize: 15
      },
      top: 10,
      left: '40%',
      subtext: '各大景区',
      subtextStyle: {
        color: 'yellowgreen',
        fontSize: 13,
        fontStyle: 'italic'
      }
    },
    //布局组件
    grid: {
      left: 60,
      right: 30,
      top: 55,
      bottom: 30
      // containLabel: true
    },
    xAxis: [
      {
        splitLine: {
          show: false
        },
        type: 'value',
        show: false,
        min: 0,
        max: 100,
        axisLine: {
          //x轴坐标轴，false为隐藏，true为显示
          show: false
        }
      }
    ],
    yAxis: [
      {
        show: true,
        splitLine: {
          show: false
        },
        axisLine: {
          show: false
        },
        type: 'category',
        axisTick: {
          show: false
        },
        inverse: true,
        // data: [1, 2, 3, 4, 5],
        axisLabel: {
          show: true,
          color: 'white'
        },
        data: ['峨眉山', '稻城亚丁', '九寨沟', '万里长城', '北京故宫']
      },
      {
        type: 'category',
        inverse: true,
        axisTick: 'none',
        axisLine: 'none',
        show: true,
        position: 'right',
        axisLabel: {
          inside: true,
          verticalAlign: 'bottom',
          lineHeight: 30,
          margin: 0, //刻度标签与轴线之间的距离
          show: true,
          textStyle: {
            color: 'rgba(255, 255, 255, 1)',
            fontFamily: 'SourceHanSansCN-Normal',
            fontSize: 15
          },
          formatter: function (value: any) {
            return value
          }
        },
        data: ['8.00w', '6.00w', '5.00w', '4.00w', '3.00w']
      }
    ],
    series: [
      {
        show: true,
        name: '',
        type: 'bar',
        data: [80, 60, 50, 40, 30],
        barWidth: 15, // 柱子宽度
        showBackground: true,
        backgroundStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 1,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: 'rgba(5, 31, 81, 1)'
              },
              {
                offset: 1,
                color: 'rgba(21, 78, 138, 1)'
              }
            ]
          }
        },
        label: {
          show: true,
          // offset: [5, -15],
          color: 'rgba(255, 255, 255, 1)',
          fontFamily: 'SourceHanSansCN-Normal',
          fontSize: 15,
          // fontWeight: 500,
          position: 'inside',
          // align: 'right',
          formatter: '{c}%'
        },
        itemStyle: {
          // barBorderRadius: [10, 10, 10, 10],
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 1,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: 'rgba(27, 54, 167, 0.33)'
              },
              {
                offset: 1,
                color: 'rgba(225, 48, 6, 1)'
              }
            ]
          }
        }
      }
    ],
    tooltip: {
      trigger: 'axis',
      show: true,
      formatter: '{b}: {c}%',
      textStyle: {
        color: 'red'
      }
    }
  })
})
</script>

<style lang="scss" scoped>
.box6 {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;
  margin-top: 10px;

  .title {
    p {
      color: white;
      font-size: 20px;
    }
  }

  .charts {
    height: calc(100% - 50px);
  }
}
</style>
